home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12779 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: aimnet.aimnet.com!not-for-mail
  2. From: jmcneill@aimnet.com (Jonathan S. McNeill)
  3. Newsgroups: comp.lang.c,comp.unix.programmer
  4. Subject: Re: Q: '\n' character
  5. Date: 2 Apr 1996 11:42:27 -0800
  6. Organization: Aimnet Corporation
  7. Sender: jmcneill@aimnet.com
  8. Message-ID: <4jrvv3$ask@aimnet.aimnet.com>
  9. References: <31616F63.481D@lava.weeg.uiowa.edu>
  10. NNTP-Posting-Host: aimnet.aimnet.com
  11.  
  12. In article <31616F63.481D@lava.weeg.uiowa.edu>,
  13. Artur Wojdat  <awojdat@lava.weeg.uiowa.edu> wrote:
  14.  
  15. >    Is there a function or some sort of way that I could remove '\n' 
  16. >charecter form the end of the string. I'm reading from two files, want to 
  17. >form one line of text and then have it printed out to stdout. I use fgets to 
  18. >read from the file and I noticed that it appends newline char at the end.
  19.  
  20. Well, if you want ultimate control over your data, just use a loop and
  21. get a character at a time.  Disclaimer:  the following is an example, has
  22. not been tested, and I agree that there are about a million ways you could do
  23. this.
  24.  
  25. /*
  26.  * loop through characters until newline or end of file
  27.  */
  28. while ( (ch = getc(stream)) != '\n' && ch != EOF ) {
  29.  
  30.     sprintf(buffer, "%s%c", buffer, ch);
  31. }
  32.  
  33. /*
  34.  * add a trailing nul character so that you can use string functions
  35.  */
  36. sprintf(buffer, "%s\0"); 
  37.  
  38. Hope this helps-
  39.  
  40. R/
  41. Jon McNeill
  42. jmcneill@aimnet.com
  43.